package cn.yunbamboos.utils;

import cn.yunbamboos.rest.service.logs.LogMetadataThreadLocal;
import com.alibaba.fastjson2.JSONObject;
import jakarta.servlet.ServletResponse;


public class WriteErrorResponseUtils {

    public static String writeErrorResponse(int code, String msg, ServletResponse response) {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json;charset=UTF-8");
        LogMetadataThreadLocal.setCode(code);
        LogMetadataThreadLocal.setMsg(msg);
        JSONObject json = new JSONObject();
        json.put("code", code);
        json.put("msg", msg);
        return json.toJSONString();
    }
}
